package com.林子祺.CAT旅游系统.dao.login;

import com.林子祺.CAT旅游系统.entity.login.LoginStatus;

import java.sql.*;

public class AccountComfirm {

    public static void checkAccount(String name, String password) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/travelsys", "root", "@Blink102417");

            String sql = "select * from user";

            stmt = conn.createStatement();

            rs = stmt.executeQuery(sql);

            while (rs.next()) {
                if (name.equals(rs.getString("name")) && password.equals(rs.getString("password"))) {
                    if(rs.getInt("admin") == 1){
                        LoginStatus.admin = true;
                    }
                    LoginStatus.name = rs.getString("name");
                    LoginStatus.money = rs.getDouble("money");
                    LoginStatus.id = rs.getInt("id");
                    LoginStatus.loginY_N = true;
                }
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }
    }

}